package com.lanou.musicbox.adapter.seekmusic;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.lanou.musicbox.R;
import com.lanou.musicbox.bean.SearchSongEntity;


import java.util.ArrayList;

/**
 * Created by 赵宝龙 on 15/10/24.
 * 搜索页面Adapter
 */
public class SeekMusicAdapter extends BaseAdapter{
    private Context mContext;

    private ArrayList<SearchSongEntity> data;

    public SeekMusicAdapter (Context mContext ,ArrayList<SearchSongEntity> data) {
        this.mContext = mContext;
        this.data = data;



    }
    @Override
    public int getCount() {
        if (data != null && data.size() > 0 )
            return  data.size();
        else
            return 0;
    }

    @Override
    public SearchSongEntity getItem(int position) {
        if (data != null && data.size() > 0)
            return data.get(position);
        else
            return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {





        ViewHolder  holder = null ;

        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.seekmusic_listview_item, null);
            //初始化
            holder = new ViewHolder();
            holder.search_list_text = (TextView) convertView.findViewById(R.id.search_list_text);


            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        SearchSongEntity songListResult = getItem(position);
        if (songListResult != null) {
            holder.search_list_text.setText(songListResult.getSongname() + "-" + songListResult.getArtistname() );
        }

        ListView songSearchLV = new ListView(mContext);

        songSearchLV.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {


            }
        });

        return convertView;
    }
    private class ViewHolder {

        private TextView search_list_text;  //歌名


    }
}
